
	.globl _i2c			;global function _i2c
	.globl _i2c_read		;global function _i2c
	.globl _i2c_write		;global function _i2c
	.globl _i2c_sendData		;global function _i2c
	.globl _i2c_readData		;global function _i2c
	.globl _rxData			;global function _i2c




	.area CSEG		;start of code segment
_i2c:
	SETB	P3.5		;Generate Start Condition
	NOP
	NOP
	

	SETB	P3.4		
	NOP
	NOP
	NOP
	CLR	P3.5
	NOP
	NOP	
	NOP
	CLR	P3.4
	NOP
	NOP
	;end of start, sending control bit
	
	
	
	;sending 0	
	CLR	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	NOP
	;end of 0


	;sending 1
	SETB	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	CLR	P3.5
	;end of 1

	
;sending 0	
	CLR	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	NOP
	;end of 0

	
	;sending 0	
	CLR	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	NOP
	;end of 0
	

	;A2 A1 A0 Sequence : 0 0 0

	;sending 0	
	CLR	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	NOP
	;end of 0

	;sending 0	
	CLR	P3.5
	NOP
	SETB	P3.4
	NOP	
	NOP
	NOP
	NOP
	NOP
	NOP	
	NOP
	CLR	P3.4
	NOP
	;end of 0

	;sending 0	
	CLR	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	NOP
	;end of 0

	;READ WRITE Bit, Writing Now

	;sending 0	
	CLR	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	NOP
	;end of 0

	
	


	;guarantee bus free time
	NOP
			;NOP
	
	;acknowledge
	SETB	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP	
	CLR	P3.4
	NOP
	NOP	
	NOP

	ret

_i2c_read:
	SETB	P3.5		;Generate Start Condition
	NOP
	NOP
	

	SETB	P3.4		
	NOP
	NOP
	NOP
	CLR	P3.5
	NOP
	NOP	
	NOP
	CLR	P3.4
	NOP
	NOP
	;end of start, sending control bit
	
	
	
	;sending 0	
	CLR	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	NOP
	;end of 0


	;sending 1
	SETB	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	CLR	P3.5
	;end of 1

	
	;sending 0	
	CLR	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	NOP
	;end of 0

	
	;sending 0	
	CLR	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	NOP
	;end of 0
	

	;A2 A1 A0 Sequence : 0 0 0

	;sending 0	
	CLR	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	NOP
	;end of 0

	;sending 0	
	CLR	P3.5
	NOP
	SETB	P3.4
	NOP	
	NOP
	NOP
	NOP
	NOP
	NOP	
	NOP
	CLR	P3.4
	NOP
	;end of 0

	;sending 0	
	CLR	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	NOP
	;end of 0

	;READ WRITE Bit, Writing Now

	;sending 1
	SETB	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	CLR	P3.5
	;end of 1

	
	


	;guarantee bus free time
	NOP
			;NOP
	
	;acknowledge
	SETB	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP	
	CLR	P3.4
	NOP
	NOP	
	NOP

	RET


_i2c_write:
	SETB	P3.5		;Generate Start Condition
	NOP
	NOP
	

	SETB	P3.4		
	NOP
	NOP
	NOP
	CLR	P3.5
	NOP
	NOP	
	NOP
	CLR	P3.4
	NOP
	NOP
	;end of start, sending control bit
	
	
	
	;sending 0	
	CLR	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	NOP
	;end of 0


	;sending 1
	SETB	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	CLR	P3.5
	;end of 1

	
;sending 0	
	CLR	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	NOP
	;end of 0

	
	;sending 0	
	CLR	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	NOP
	;end of 0
	

	;A2 A1 A0 Sequence : 0 0 0

	;sending 0	
	CLR	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	NOP
	;end of 0

	;sending 0	
	CLR	P3.5
	NOP
	SETB	P3.4
	NOP	
	NOP
	NOP
	NOP
	NOP
	NOP	
	NOP
	CLR	P3.4
	NOP
	;end of 0

	;sending 0	
	CLR	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	NOP
	;end of 0

	;READ WRITE Bit, Write Selected

	;sending 0	
	CLR	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	NOP
	;end of 0

	
	


	;guarantee bus free time
	NOP
			;NOP
	
	;acknowledge
	SETB	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP	
	CLR	P3.4
	NOP
	NOP	
	NOP

	RET





















_i2c_sendData:

		;write to port
	
	;sending 1
	SETB	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	CLR	P3.5
	;end of 1

;sending 0	
	CLR	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	NOP
	;end of 0




;sending 1
	SETB	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	CLR	P3.5
	;end of 1

;sending 0	
	CLR	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	NOP
	;end of 0

;sending 1
	SETB	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	CLR	P3.5
	;end of 1

;sending 0	
	CLR	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	NOP
	;end of 0

;sending 1
	SETB	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	CLR	P3.5
	;end of 1

;sending 0	
	CLR	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	NOP
	;end of 0






	;guarantee bus free time
	NOP
			;NOP
	
	;acknowledge
	SETB	P3.5
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP	
	CLR	P3.4
	NOP
	NOP	
	NOP
	RET



_i2c_readData:

		;write to port
	
	;sending sca-0
	
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	
	;end of 1

;sending sca-1	
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	
	;end of 0




;sending sca-2
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	
	;end of 1

;sending sca-3
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	
	;end of 1

;sending sca-4
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	
	;end of 1

;sending sca-5
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	
	;end of 1

;sending sca-6
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	
	;end of 1

;sending sca-7
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	
	;end of 1


;sending sca-7
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	SETB	P3.4
	NOP
	NOP
	NOP
	NOP	
	NOP
	NOP
	NOP
	CLR	P3.4
	
	;end of 1





	
	;guarantee bus free time
	NOP
	CLR	P3.5
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	SETB	P3.4		;Generate Stop Condition
	NOP
	NOP	
	NOP
	SETB	P3.5
	NOP
	NOP
	NOP
	CLR	P3.4
	NOP
	NOP
	;end of start, sending control bit






_rxData:
;	main.c:74: tmp=(char *)malloc(1);
;	genCall
;	Peephole 182.b	used 16 bit load of dptr
	mov	dptr,#0x0001
	lcall	_malloc
	mov	r2,dpl
	mov	r3,dph
;	genCast
	mov	r4,#0x0
;	main.c:75: *tmp='h';
;	genPointerSet
;	genGenPointerSet
	mov	dpl,r2
	mov	dph,r3
	mov	b,r4
	mov	a,#0x68
	lcall	__gptrput
;	main.c:76: return tmp;
;	genRet
	mov	dpl,r2
	mov	dph,r3
	mov	b,r4
;	Peephole 300	removed redundant label 00101$
	ret










	
	
	
		
	
